(function() {
    'use strict';

    /**
     * @ngdoc directive
     * @name webApp.directive:loginDialog
     * @description
     * # loginDialog
     */
    angular.module('webApp')
        .run(["$templateCache", "dataService",
            function($templateCache, dataService) {
                var tplName = "views/directives.liuyan.html";
                dataService.tpl(tplName).then(function(html) {
                    $templateCache.put(tplName, html);
                });
            }
        ])
        .directive('liuyan', ["$rootScope", "helper", function($rootScope, helper) {
            return {
                restrict: 'EA',
                template: "<span><a href='javascript:;' class='sui-btn btn-success' ng-click='showPro()'>添加留言</a>",
                // require:'ngModel',
                scope: {
                    // ngModel:"=",
                    // callback:"&",
                },
                controller: ['$scope', 'authService', 'sessionService', 'dataService', '$compile', 'helper', '$templateCache', '$timeout', function($scope, authService, sessionService, dataService, $compile, helper, $templateCache, $timeout) {
                    $scope.productcat = {};
                    $scope.showPro = function() {
                        showSelect();
                    }

                    function showSelect() {
                        $scope.error = null;
                        //弹出
                        $.alert({
                            backdrop: "static",
                            keyboard: true,
                            title: '{{"用户留言"|translate}}',
                            body: $templateCache.get("views/directives.liuyan.html"),
                            // okBtn: '{{"login"|translate}}',
                            closeBtn: true,
                            hasfoot: false,
                            transition: true,
                            width: 'large',
                            height: 400,
                            show: function(e) {
                                $compile($(e.currentTarget).contents())($scope);
                            },
                            okHide: function(e) {

                            },
                            shown: function(e) {}
                        });
                    }

                    //测试留言
                    $scope.submitForm = function() {
                        var query = {
                            content: {
                                name: $scope.liuyan.name,
                                phone: $scope.liuyan.phone,
                                content: $scope.liuyan.content,
                            }
                        };
                        
                        // var query = {
                        //     content: {
                        //         store_id: $rootScope.store_id,
                        //         qq:1111111,
                        //         phone:111111111111,
                        //         wxapp_id:"wx82bd84ec09fed74e",
                        //         name:"ddadsasdas",
                        //         remarks: "备注的的的",
                        //     }
                        // };
                        //  backliuyanAdd  buyerliuyanAdd
                        dataService.backliuyanAdd(query).then(function(r) {
                            if (r.back_liuyan_id) {
                                helper.myAlert("留言成功");
                                rmAlert();
                            }
                        });
                    }
                }],
                link: function(scope, elem, attrs, ctr) {

                }
            }
        }]);
})();